package com.think.teaching.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.think.teaching.model.ExamResult;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.LinkedHashMap;
import java.util.List;

/**
 * <p>
 * 学生考试结果 Mapper 接口
 * </p>
 *
 * @author think
 * @since 2020-08-12
 */
public interface ExamResultMapper extends BaseMapper<ExamResult> {


    //根据 result id 返回对应 question 实体
    @Select("SELECT id, question_id, answer as userAnswer FROM exam_result" +
            " WHERE " +
            "result_id=#{id}")
    @Result(column = "question_id",property = "question",one = @One(select ="com.think" +
            ".teaching.mapper.ExamResultMapper.getQuestions",fetchType = FetchType.EAGER))
    List<LinkedHashMap<String,Object>> getExamResults(Integer id);

    /*
     由上层方法 getExamResults 调用，传入 question id，返回对应 question 的指定 Info
     */
    @Select("SELECT id as questionId,content,analyzing,answer as referenceAnswer FROM question " +
            "WHERE " +
            "id=#{questionId}")
    LinkedHashMap<String,Object> getQuestions(Integer questionId);


}
